var paymentDesc = function(){
    var html = '<div style="margin: 10px">\n' +
        '<div style="margin-top: 10px;margin-right: 20px">\n' +
/*        '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
        '        <div class="layui-form-item">\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">仓库名</script></label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="text" name="keyword" id="keyword" autocomplete="off" placeholder="请输入仓库名"\n' +
        '                           class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-inline">\n' +
        '                <label class="layui-form-label">状态</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <select name="searchStockStatus" lay-search="">\n' +
        '                        <option value=""></option>\n' +
        '                        <option value="0">启用</option>\n' +
        '                        <option value="1">禁用</option>\n' +
        '                    </select>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '            <div class="layui-form-item">\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">起始时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="beginDate" id="date1" lay-verify="datetime" placeholder="起始时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <label class="layui-form-label">截至时间</label>\n' +
        '                    <div class="layui-input-inline">\n' +
        '                        <input type="text" name="endDate" id="date2" lay-verify="datetime" placeholder="结束时间"\n' +
        '                               autocomplete="off" class="layui-input">\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '                <div class="layui-inline">\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <button class="layui-btn" lay-submit="" lay-filter="demo2">立即搜索</button>\n' +
        '                    </div>\n' +
        '                </div>\n' +
        '            </div>\n' +
        '    </form>\n' +
        '</div>\n' +*/
        '    <hr style="margin-bottom: 20px">\n' +
        '    <div style="margin-left: 10px;margin-right: 10px">\n' +
        '        <table class="layui-hide" id="demo" lay-filter="test"></table>\n' +
        '    </div>\n' +
        '    <input id="addStockHidden" value="" hidden="hidden">' +
        '</div>';

    layui.use(['table', 'form', 'jquery', 'element', 'laydate'], function () {
        var table = layui.table
            , form = layui.form
            , $ = layui.jquery
            , laydate = layui.laydate
            , element = layui.element;
        $("#mainbody").html(html);
        form.render();

        var tableRender = function () {
            //执行一个 table 实例

            table.render({
                elem: '#demo'
                //, height: 480
                , id:"paymentDescList"
                , url: 'paymentDesc/getList' //数据接口
                , title: '签到明细表'
                , page: true //开启分页
                , toolbar: 'default'
                , limit: 10
                , limits: [10, 20, 30]
                , cols: [[ //表头
                    {type: 'checkbox'}
                    ,{type: 'numbers',title: '序号',width: 80}
                    , {field: 'paymentName', align: 'center', title: '付款渠道', width: 180}
                    , {field: 'paymentDescContent', align: 'center', title: '内容', width: 120}

                ]]
            });
        }

        //初始化表格
        tableRender();


        var openUpdateSignIn = function(data){
            layer.open({
                title: ['添加付款详情', 'font-size:18px;']
                , shade: 0.6 //遮罩透明度
                , area: '400px'//宽度
                , type: 2
                , anim: 1 //0-6的动画形式，-1不开启
                , content: '/paymentDesc/editButton/'+data[0].id
                , success: function (layero, index) {
                    //layer高度自适应
                    layer.iframeAuto(index);
                }
                , end: function (data) {
/*                    layer.msg('修改成功', {
                        icon: 1,
                        time: 200 //2秒关闭（如果不配置，默认是3秒）
                    });*/
                    table.reload('paymentDescList');
                }
            });
        }

        var openAddSignIn = function () {
            layer.open({
                title: ['添加付款详情', 'font-size:18px;']
                , shade: 0.6 //遮罩透明度
                , area: '300px'//宽度
                , type: 2

                , anim: 1 //0-6的动画形式，-1不开启
                , content: '/paymentDesc/addButton'
                , success: function (layero, index) {
                    //layer高度自适应
                    layer.iframeAuto(index);
                }
                , end: function (data) {
/*                    layer.msg('添加成功', {
                        icon: 1,
                        time: 200 //2秒关闭（如果不配置，默认是3秒）
                    });*/
                    table.reload("paymentDescList")
                }
            })
        }

        var openDeleteSignIn = function(json){
            layer.confirm('确定删除勾选数据吗？', {icon: 3, title:'提示'}, function(index){
                var arr = new Array();
                for(var i =0 ;i < json.length;i++){
                    arr.push(json[i].id);
                }
                $.ajax({
                    type: "POST",
                    url: "/paymentDesc/delete",
                    traditional: true,
                    data: JSON.stringify(arr),
                    dataType: "json",
                    contentType: "application/json",
                    success: function (data) {
                        layer.msg('删除成功！', {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        table.reload("paymentDescList");
                    },
                    error: function () {
                        console.log("调用删除方法失败！");
                    }
                });
            });
        }

        //监听头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    console.log($("#xxxx").html());
                    openAddSignIn();
                    break;
                case 'update':
                    var data = checkStatus.data;
                    if(data.length<1){
                        layer.msg('未选择数据！',
                            {icon: 2, time: 500}
                        )
                    }else{
                        openUpdateSignIn(data);
                    }
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    if(data.length<1){
                        layer.msg('未选择数据！',
                            {icon: 2, time: 500}
                        )
                    }else{
                        openDeleteSignIn(data);
                    }
                    break;
            };
        });




        //监听搜索按钮
/*        form.on('submit(demo2)', function (data) {
            var status = data.field.searchStockStatus;
            var keyword = $("#keyword").val();
            var begin = $("#date1").val();
            var end = $("#date2").val();
            //table.reload();
            table.reload('stockList', {
                where: {"keyword": keyword, "beginStr": begin, "endStr": end, "status": status}
            });
        });*/


    });
}